package com.huadao.cart_ccs.experiment.afterCulture;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.base.BaseActivity;
import com.huadao.cart_ccs.common.dialog.DialogFragmentHelper;
import com.huadao.cart_ccs.common.dialog.IDialogResultListener;
import com.huadao.cart_ccs.experiment.sterilization.UltravioletSterilizationActivity;

public class AfterCultureActivity extends BaseActivity implements IAfterCultureContract.IAfterCultureView {

    private ImageView door;
    private Button btn_open_door;
    private Button btn_close_door;

    private AfterCulturePresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_after_culture);
        presenter=new AfterCulturePresenter(this);
        door=findViewById(R.id.door);
        btn_open_door=findViewById(R.id.btn_open_door);
        btn_close_door=findViewById(R.id.btn_close_door);
        door.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                operateDoor();
            }
        });
        btn_open_door.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.openDoor();
            }
        });
        btn_close_door.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.closeDoor();
            }
        });
        findViewById(R.id.btn_sterilization).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogFragmentHelper.showConfirmDialog(AfterCultureActivity.this, "进入杀菌", "确认进入杀菌消毒", new IDialogResultListener<Integer>() {
                    @Override
                    public void onDataResult(Integer result) {
                        if(result==DialogInterface.BUTTON_POSITIVE) {
                            Intent intent = new Intent(AfterCultureActivity.this, UltravioletSterilizationActivity.class);
                            Bundle bundle=new Bundle();
                            bundle.putInt("sterilizationTime",30*60);
                            bundle.putBoolean("afterCulture",true);
                            intent.putExtras(bundle);
                            startActivity(intent);
                            AfterCultureActivity.this.finish();
                        }
                    }
                },true);

            }
        });
    }

    private void operateDoor(){
        DialogFragmentHelper.showTwoOperateDialog(this, getString(R.string.door), null, R.string.open_door, R.string.close_door, new IDialogResultListener<Integer>() {
            @Override
            public void onDataResult(Integer result) {
                if (result == DialogInterface.BUTTON_POSITIVE) {
                    presenter.openDoor();
                } else if (result == DialogInterface.BUTTON_NEGATIVE) {
                    presenter.closeDoor();
                }
            }
        }, true);
    }

    @Override
    public void onDoorOpen() {
        showToast("开门");
    }

    @Override
    public void onDoorClose() {
        showToast("关门");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detachView();
    }
}
